Implement debug-on-event
authorDaniel Colascione <dan.colascione@gmail.com>
Tue, 26 Apr 2011 11:26:05 +0000 (04:26 -0700)
committerDaniel Colascione <dan.colascione@gmail.com>
Tue, 26 Apr 2011 11:26:05 +0000 (04:26 -0700)
etc/ChangeLog
etc/DEBUG
lisp/ChangeLog
lisp/cus-start.el
src/ChangeLog
src/eval.c
src/keyboard.c
src/lisp.h

index ca7d924ad0cca41e3430ad81821771e0f1916f6b..2bfc2375109b931dd2523f0400fbdad43c8e3db8 100644 (file)
@@ -1,3 +1,8 @@
+2011-04-26  Daniel Colascione  <dan.colascione@gmail.com>
+
+       * Document debug-on-event default behavior and utility for
+       debugging.
+
 2011-04-22  Noah Friedman  <friedman@splode.com>
 
        * emacs-buffer.gdb: Add trailing underscores to appropriate member
index c8fd48c6bfaf8ce22f2e2501ad1c353e0f7cf5df..625a76ac952128280873e4bfb009a9ec8bc73c17 100644 (file)
--- a/etc/DEBUG
+++ b/etc/DEBUG
@@ -405,6 +405,11 @@ stepping, you will see where the loop starts and ends.  Also, examine
 the data being used in the loop and try to determine why the loop does
 not exit when it should.
 
+You can also trying sending Emacs SIGUSR2, which, if `debug-on-event'
+has its default value, will cause Emacs to attempt to break it out of
+its current loop and into the Lisp debugger.  This feature is useful
+when a C-level debugger is not conveniently available.
+
 ** If certain operations in Emacs are slower than they used to be, here
 is some advice for how to find out why.
 
index fb6d09d3a9e6645a1583f6e3f76ea0a03f229fd4..699796019bb78ae731a2e8b9529539d6caa8eb36 100644 (file)
@@ -1,3 +1,7 @@
+2011-04-26  Daniel Colascione  <dan.colascione@gmail.com>
+
+       * cus-start.el (all): Define customization for debug-on-event.
+
 2011-04-26  Daniel Colascione <dan.colascione@gmail.com>
 
        * subr.el (shell-quote-argument): Escape correctly under Windows.
index 1188d37150a694eee660889755e71628bc4512d3..6113a4321c5677e238ce661c6ccbf6274437ee3b 100644 (file)
@@ -259,6 +259,11 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of
             (suggest-key-bindings keyboard (choice (const :tag "off" nil)
                                                    (integer :tag "time" 2)
                                                    (other :tag "on")))
+             (debug-on-event debug
+                             (choice (const :tag "None" nil)
+                                     (const :tag "When sent SIGUSR1" sigusr1)
+                                     (const :tag "When sent SIGUSR2" sigusr2))
+                             "24.1")
 
 ;; This is not good news because it will use the wrong
 ;; version-specific directories when you upgrade.  We need
index 0e672a0a19a2f5160d8024a124283858cd341078..5f17aa929dafa681a1619454ea5f7a5eeec70d74 100644 (file)
@@ -1,3 +1,11 @@
+2011-04-26  Daniel Colascione <dan.colascione@gmail.com>
+
+       * lisp.h (Qdebug): List symbol.
+       * eval.c (Qdebug): restore global linkage.
+       * keyboard.c (debug-on-event): New variable.
+       (handle_user_signal): Break into debugger when debug-on-event
+       matches the current signal symbol.
+
 2011-04-25  Dan Nicolaescu  <dann@ics.uci.edu>
 
        * alloc.c (check_sblock, check_string_bytes)
index d1f327021e6a5009224bbc15f110c67a63db9a0f..8716ad78468a12dfaf9380d8a649f6f57f6891eb 100644 (file)
@@ -88,7 +88,7 @@ static Lisp_Object Qdebug_on_error;
 static Lisp_Object Qdeclare;
 Lisp_Object Qinternal_interpreter_environment, Qclosure;
 
-static Lisp_Object Qdebug;
+Lisp_Object Qdebug;
 
 /* This holds either the symbol `run-hooks' or nil.
    It is nil at an early stage of startup, and when Emacs
index c601649ebcae06473afc46ae60253448558fe038..11cdeaf469c8ef96d69bd8a74024112b6029d3ba 100644 (file)
@@ -7228,12 +7228,29 @@ handle_user_signal (int sig)
 {
   int old_errno = errno;
   struct user_signal_info *p;
+  const char* special_event_name = NULL;
 
   SIGNAL_THREAD_CHECK (sig);
-
+  
+  if (SYMBOLP (Vdebug_on_event))
+    special_event_name = SDATA (SYMBOL_NAME (Vdebug_on_event));
+  
   for (p = user_signals; p; p = p->next)
     if (p->sig == sig)
       {
+        if (special_event_name &&
+            strcmp (special_event_name, p->name) == 0)
+          {
+            /* Enter the debugger in many ways.  */
+            debug_on_next_call = 1;
+            debug_on_quit = 1;
+            Vquit_flag = Qt;
+            Vinhibit_quit = Qnil;
+
+            /* Eat the event.  */
+            break;
+          }
+        
        p->npending++;
 #ifdef SIGIO
        if (interrupt_input)
@@ -12165,6 +12182,17 @@ text in the region before modifying the buffer.  The next
 `deactivate-mark' call uses this to set the window selection.  */);
   Vsaved_region_selection = Qnil;
 
+  DEFVAR_LISP ("debug-on-event",
+               Vdebug_on_event,
+               doc: /* Enter debugger on this event.  When Emacs
+receives the special event specifed by this variable, it will try to
+break into the debugger as soon as possible instead of processing the
+event normally through `special-event-map'.
+
+Currently, the only supported values for this
+variable are `sigusr1' and `sigusr2'.  */);
+  Vdebug_on_event = intern_c_string ("sigusr2");
+
   /* Create the initial keyboard. */
   initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
   init_kboard (initial_kboard);
index 07b2cb0b1ef2ca820ba26f28bab6e15f4421b468..44df38e9fa6141103a2845acb24ccf1120ed417e 100644 (file)
@@ -2796,7 +2796,7 @@ extern void syms_of_lread (void);
 
 /* Defined in eval.c.  */
 extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qdefun, Qmacro;
-extern Lisp_Object Qinhibit_quit, Qclosure;
+extern Lisp_Object Qinhibit_quit, Qclosure, Qdebug;
 extern Lisp_Object Qand_rest;
 extern Lisp_Object Vautoload_queue;
 extern Lisp_Object Vsignaling_function;